﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Linq;
using DocumentFormat.OpenXml.Packaging;

namespace WebApplication2
{
    public partial class _Default : System.Web.UI.Page
    {
        string text;
        public static XDocument LoadXDocument(OpenXmlPart part)
        {
            XDocument xdoc;
            using (StreamReader streamReader = new StreamReader(part.GetStream()))
                xdoc = XDocument.Load(XmlReader.Create(streamReader));
            return xdoc;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            const string filename = "C://soubor.docx";
            using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(filename, true))
            {
                MainDocumentPart mainPart = wordDoc.MainDocumentPart;
                StyleDefinitionsPart styleDefinitionsPart = mainPart.StyleDefinitionsPart;
                XDocument xDoc = LoadXDocument(mainPart);
                XDocument styleDoc = LoadXDocument(styleDefinitionsPart);
                string XML = xDoc.ToString();
                using (StreamWriter zapis = new StreamWriter("soubor.xml"))
                {
                    zapis.Write(XML);
                }
                XmlReader cteni = new XmlTextReader("soubor.xml");
                while (cteni.Read())
                {
                    if (cteni.Name == "w:t")
                    {
                        text = cteni.ReadString();
                        //Console.Write(cteni.ReadString());
                    }
                }
                texta.Text = text;
                cteni.Close();
                File.Delete("soubor.xml");
            }
            
        }

        protected void vybercestu(object sender, EventArgs e)
        {
            
        }
    }
}
